|
7 | 7 | from django.contrib.auth.models import User
|
8 | 8 | from django.contrib.contenttypes.models import ContentType
|
9 | 9 | from django.contrib.sessions.backends.base import SessionBase
|
10 |
| -from django.db import transaction |
11 | 10 |
|
12 | 11 | from kitsune.flagit.models import FlaggedObject
|
13 | 12 | from kitsune.llm.questions.classifiers import ModerationAction
|
14 | 13 | from kitsune.products.models import Product, Topic
|
15 | 14 | from kitsune.questions.models import Answer, Question
|
16 |
| - |
17 |
| -# from kitsune.tags.models import SumoTag |
18 | 15 | from kitsune.users.models import Profile
|
19 | 16 | from kitsune.wiki.utils import get_featured_articles as kb_get_featured_articles
|
20 | 17 | from kitsune.wiki.utils import has_visited_kb
|
@@ -189,25 +186,21 @@ def process_classification_result(
|
189 | 186 | reason=FlaggedObject.REASON_SPAM,
|
190 | 187 | )
|
191 | 188 | case _:
|
192 |
| - if not (topic_title := result["topic_result"].get("topic")): |
193 |
| - return |
194 |
| - |
195 |
| - try: |
196 |
| - topic = Topic.active.get(title=topic_title, visible=True) |
197 |
| - except (Topic.DoesNotExist, Topic.MultipleObjectsReturned): |
198 |
| - return |
199 |
| - |
200 |
| - with transaction.atomic(): |
201 |
| - flag_question( |
202 |
| - question, |
203 |
| - by_user=sumo_bot, |
204 |
| - notes=( |
205 |
| - "LLM classified as {topic.title}, for the following reason:\n" |
206 |
| - f"{result['topic_result']['reason']}" |
207 |
| - ), |
208 |
| - status=FlaggedObject.FLAG_ACCEPTED, |
209 |
| - ) |
210 |
| - if topic != question.topic: |
| 189 | + if topic_title := result["topic_result"].get("topic"): |
| 190 | + try: |
| 191 | + topic = Topic.active.get(title=topic_title, visible=True) |
| 192 | + except (Topic.DoesNotExist, Topic.MultipleObjectsReturned): |
| 193 | + return |
| 194 | + else: |
| 195 | + flag_question( |
| 196 | + question, |
| 197 | + by_user=sumo_bot, |
| 198 | + notes=( |
| 199 | + "LLM classified as {topic.title}, for the following reason:\n" |
| 200 | + f"{result['topic_result']['reason']}" |
| 201 | + ), |
| 202 | + status=FlaggedObject.FLAG_ACCEPTED, |
| 203 | + ) |
211 | 204 | if question.topic:
|
212 | 205 | question.tags.remove(question.topic.slug)
|
213 | 206 | question.topic = topic
|
|
0 commit comments